<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BoardClass
 *
 * @author WIN7
 */
class BoardClass {
    //put your code here
    public $total;
    public $finish;
    public $percent;

       public function __construct() {
           if (isset(Yii::app()->session['saleId'])) {
               $id = Yii::app()->session["saleId"];
           } else {
               $id = 0;
           }           
       try{
                $connection=Yii::app()->db;   // assuming you have configured a "db" connection
                
                $query="SELECT * FROM os_order
                    WHERE os_order.sale_id =".$id;
                $command=$connection->createCommand($query);
                $dataReader=$command->query();
                $rows_order = array();
                $this->finish = 0;
                while(($row=$dataReader->read())!==false) {
                    $rows_order[]=$row;
                }
                if (empty($rows_order)) {
                    $this->finish = 0;
                    $this->total = 0;
                    $this->percent = 0;
                } else {
                foreach ($rows_order as $key) {
                    if ($key['IsFinish'] == 1) 
                        $this->finish++;
                }
                $this->total = count($rows_order);
                $this->percent = $this->finish/$this->total * 100; }
                }catch(Exception $e){
                $result=array('data'=>'','status'=>'fail','error'=>$e->getMessage());
                 echo $string=json_encode($result);
             }
   }
    
    public function order() {
                return $this->finish."/".$this->total;                        
    }
    
    
}

?>
